pkgname=sdl2
pkgver=2.0.5
pkgrel=0
_pkgname=SDL2
pkgdesc="A development library designed to provide low level access to audio, keyboard, mouse, joystick and graphics"
url="http://www.libsdl.org"
arch="all"
license="zlib"
depends="directfb"
depends_dev="alsa-lib-dev libxcursor-dev libxrandr-dev libxrender-dev mesa-dev directfb"
makedepends="$depends_dev"
subpackages="$pkgname-dev"
source="https://www.libsdl.org/release/$_pkgname-$pkgver.tar.gz
	altivec-fixes.patch
	0001-fix-c90-errors.patch"

builddir="$srcdir/$_pkgname-$pkgver"

prepare(){
    cd "$builddir"

    # first apply patches in specified order
    for i in $source; do
    	case $i in
	*.patch)
		msg "Applying $i..."
		if ! patch -s -p1 -N -i "$srcdir"/$i; then
			echo $i >>failed
			_patch_failed=1
		fi
        ;;
        esac
    done

    if ! [ -z "$_patch_failed" ]; then
	error "The following patches failed:"
	cat failed
	return 1
    fi


}

build() {
    cd "$builddir"
    ./configure \
    --build=$CBUILD \
    --host=$CHOST \
    --prefix=/usr \
    --enable-alsa \
    --enable-clock_gettime \
    --disable-arts \
    --disable-esd \
    --disable-nas \
    --disable-rpath \
    --with-x \
    --enable-video-directfb
    make
}

package() {
    cd "$builddir"
    make DESTDIR="$pkgdir" install || return 1
}

sha512sums="6401f5df08c08316c09bc6ac5b28345c5184bb25770baa5c94c0a582ae130ddf73bb736e44bb31f4e427c1ddbbeec4755a6a5f530b6b4c3d0f13ebc78ddc1750  SDL2-2.0.5.tar.gz
aad37129e8d1259fcceea087794aa45f7d94a5b0b09275a72e20ae53809a587f8a59dba05c9bd763012e6471d6d9d87739e282bcbb7df4de5c66d06d9e23d8d3  altivec-fixes.patch
25dbfa65f15040564f2345c235e8997fcc60e81e03691afcd75b3d5f982941220d4a2b7710de1e40b581b63632f1b667befbc819513a785da01ad40d6ce1ef5f  0001-fix-c90-errors.patch"
